import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class hurdleChoice extends JFrame {
    //初始水平为0
     public int currentLevel = 0;
    //设置五个关卡的行、列、炸弹数
    public int[][] hurdleassign = {
            {9,9,10},{12,12,20},
            {16,16,30},{20,20,60},{24,24,80}
    };
    //五个关卡的按钮
    public JButton[] hurdleButtons = new JButton[hurdleassign.length];
    //窗口
    public hurdleChoice() {
        setTitle("关卡模式-解构者の试炼");
        setSize(1500, 800);
        setLocationRelativeTo(null); //
        setLayout(new GridLayout(9,1,10,10));
        JLabel title = new JLabel("请选择关卡",SwingConstants.CENTER);
        title.setFont(new Font("宋体",Font.BOLD,20));
        add(title);
        for(int i=0;i<hurdleassign.length;i++){
            int level1=i;
            hurdleButtons[i] = new JButton("关卡"+(i+1));
            hurdleButtons[i].setEnabled(i==0);
            hurdleButtons[i].setBounds(900, 300+(i*100), 200, 60);
            hurdleButtons[i].addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    startLevel(level1);
                }
            });
            add(hurdleButtons[i]);
        }
        JButton exitButton = new JButton("退出关卡模式");
        exitButton.setBounds(900,800,200,60);
        exitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });
        add(exitButton);
        setVisible(true);
    }
    public void startLevel(int x){
        int rows = hurdleassign[x][0];
        int cols = hurdleassign[x][1];
        int tntNum = hurdleassign[x][2];

        JFrame gameFrame = new JFrame("关卡 "+(x+1));
        gamePanel panel = new gamePanel(rows,cols,tntNum){
            public void checkWin(){
                super.checkWin();
                if(gameOver){
                    unlockNextLevel(x);
                }
            }
        };
        gameFrame.setContentPane(panel);
        gameFrame.pack();
        gameFrame.setVisible(true);
        gameFrame.setLocationRelativeTo(null);
    }
    public void unlockNextLevel(int x){
        if(x + 1<hurdleassign.length){
            hurdleButtons[x+1].setEnabled(true);
        }else{
            JOptionPane.showMessageDialog(this,"伟大的解构者,恭喜你完成所有试炼关卡！\n" +
                    "虽然雷域危机四伏,但也请你不要停下来啊！","伟大的起始", JOptionPane.INFORMATION_MESSAGE);
        }
    }
}